#define  _CRT_SECURE_NO_WARNINGS
#include <vector>
using namespace std;
#include <algorithm>
class Solution {
public:
    int longestConsecutive(vector<int>& nums) {
        if (nums.empty()) return 0;
        sort(nums.begin(), nums.end());
        int ret = 1, tmp = 1;
        for (int i = 1; i < nums.size(); i++)
        {
            if (nums[i - 1] == nums[i] - 1)
                tmp++;
            else if (nums[i - 1] == nums[i])
                continue;
            else if (ret < tmp)
            {
                ret = tmp;
                tmp = 1;
            }
        }
        ret = max(ret, tmp);
        return ret;
    }
};

int main()
{
    vector<int> v{ 9,1,-3,2,4,8,3,-1,6,-2,-4,7 };
    Solution().longestConsecutive(v);
}